//
//  FZHomeTabViewCell.swift
//  MyWeiBo
//
//  Created by fangzhengwei on 2017/3/30.
//  Copyright © 2017年 fangzhengwei. All rights reserved.
//

import UIKit
import SnapKit
class FZHomeTabViewCell: UITableViewCell {
    
    var statusModel : FZStatusViewModel?{
        
        didSet {
            orginView.statusOriginModel = statusModel
            toolBarView.statusToolBarModel = statusModel
            reportView.statusReportModel = statusModel
            
            toolBarTopConstraint?.deactivate()
            
            if statusModel?.statusModel?.retweeted_status == nil {
                
               toolBarView.snp.makeConstraints({ (make) in
                  toolBarTopConstraint = make.top.equalTo(orginView.snp.bottom).offset(1).constraint
               })
               reportView.isHidden = true
            }else{
                
                toolBarView.snp.makeConstraints({ (make) in
                    toolBarTopConstraint = make.top.equalTo(reportView.snp.bottom).offset(1).constraint
                })
                reportView.isHidden = false
            }
        }
    }
    
    var toolBarTopConstraint: Constraint?
    
    fileprivate lazy var reportView : FZReportView = FZReportView()
    
    fileprivate lazy var orginView : FZOriginView = FZOriginView()
    
    fileprivate lazy var toolBarView : FZHomeToolBar = FZHomeToolBar()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        contentView.addSubview(orginView)
        contentView.addSubview(toolBarView)
        contentView.addSubview(reportView)
        selectionStyle = .none
        setupUI()
    }
    
    func setupUI() {
        
       orginView.snp.makeConstraints { (make) in
        make.left.right.equalTo(contentView)
        make.top.equalTo(contentView).offset(10)
        
      }
        
      reportView.snp.makeConstraints { (make) in
        make.top.equalTo(orginView.snp.bottom)
        make.left.right.equalTo(self)
      }
        
      toolBarView.snp.makeConstraints { (make) in
        toolBarTopConstraint = make.top.equalTo(reportView.snp.bottom).offset(1).constraint
        make.left.right.equalTo(contentView)
        make.bottom.equalTo(contentView).offset(0)
      }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
